<?php

class Controller{
	public $module;
	private static $modules = array();
	private $actionFile = "conf/mod.ini";

	public function parseFile(){
		$this->modules = parse_ini_file($this->actionFile, true);
		return $this->modules;
	}

	public function getAction(){
		return false;
	}

	public function fetchAction(){
		$action = "actions/".$this->modules[$this->module]['action'];
		return $this->checkActionFile($action);
	}

	public function checkActionFile($action = ""){
		if(file_exists($action) && $action!="actions/"){
			$file = file_get_contents($action);
			$hasString = strstr($file, CONST_SECURITY_KEY);
			if($hasString !== FALSE){
				return $action;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}

	public function getPage(){
		return false;
	}

	public function fetchPage(){
		$page = "pages/".$this->modules[$this->module]['page'];
		if(file_exists($page) && $page!="pages/")
			return $page;
		else
			return false;
	}

	public function setPage($path){
		$this->modules[$this->module]['page'] = "pages/".$path;
	}
	
	public function getTemplate(){
		$template = "templates/".$this->modules[$this->module]['template'];
		if(file_exists($template) && $template!="templates/")
			return $template;
		else
			return "templates/default.php";
	}
	
	public function isAjax(){
		if(isset($this->modules[$this->module]['ajax']) && $this->modules[$this->module]['ajax'])
			return true;
		else
			return false;
	}
	
	public function redirect($url, $absolute=false){
		if($absolute)
			$url = WEB_ROOT.($url[0]=='/' ? '':'/').$url;
			header("Location: $url");
			exit();
	}
}

?>